/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package l2s.authserver;

import l2s.commons.configuration.Config;

/**
 * <p>
 * This class is used to represent session keys used by the client to authenticate in the gameserver
 * </p>
 * <p>
 * A SessionKey is made up of two 8 bytes keys. One is send in the {@link l2s.authserver.network.serverpackets.AuthOk AuthOk} packet and the other is sent in {@link l2s.authserver.network.serverpackets.PlayOk PlayOk}
 * </p>
 * @author -Wooden-
 */
public class SessionKey
{
	public int playOkID1;
	public int playOkID2;
	public int AuthOkID1;
	public int AuthOkID2;
	
	public SessionKey(int AuthOk1, int AuthOk2, int playOK1, int playOK2)
	{
		playOkID1 = playOK1;
		playOkID2 = playOK2;
		AuthOkID1 = AuthOk1;
		AuthOkID2 = AuthOk2;
	}
	
	@Override
	public String toString()
	{
		return "PlayOk: " + playOkID1 + " " + playOkID2 + " AuthOk:" + AuthOkID1 + " " + AuthOkID2;
	}
	
	public boolean checkLoginPair(int AuthOk1, int AuthOk2)
	{
		return (AuthOkID1 == AuthOk1) && (AuthOkID2 == AuthOk2);
	}
	
	/**
	 * Only checks the PlayOk part of the session key if server doesnt show the licence when player logs in.
	 * @param key
	 * @return true if keys are equal.
	 */
	public boolean equals(SessionKey key)
	{
		// when server doesnt show licence it deosnt send the AuthOk packet, client doesnt have this part of the key then.
		if (Config.SHOW_LICENCE)
		{
			return ((playOkID1 == key.playOkID1) && (AuthOkID1 == key.AuthOkID1) && (playOkID2 == key.playOkID2) && (AuthOkID2 == key.AuthOkID2));
		}
		
		return ((playOkID1 == key.playOkID1) && (playOkID2 == key.playOkID2));
	}
}